Instructions for Replicating Analyses in Anzia, Jares, and Malhotra (2022)
* Note: You must have R, R Studio, Stata, Python, and Jupyter notebooks
* installed to run the programs in this replication file. R and Stata
* suffice for the regression analyses; Python is only used for creating
* the descriptive statistics figures. The authors used Stata 17, R version 
* 4.0.3, and Python 3.8.5 for these analyses. Note that a codebook for
* "Survey Respondent Data for APSR Analyses.dta" has been included in
* the replication materials.

Steps for reproducing all regression analyses
1. Make sure you have the Stata backage ebalance installed (Hainmueller et al 2011).
   This can be done with the Stata command-line syntax "ssc install ebalance, all replace"
2. Make sure the following R packages are installed. Versions of packages used by
   the authors are provided in parentheses.
   * foreign (0.8.82)
   * haven (2.4.3)
   * tidyverse (1.3.1)
   * estimatr (0.30.6)
   * sandwich (3.0.0)
   * broom (0.7.12)
   * lmtest (0.9.38)
   * MASS (7.3.53)
   * dotwhisker (0.6.0)
   * reshape2 (1.4.4)
   * rcpp (1.0.7) [Not imported directly, but make sure this is updated]
3. In each of the four programs in the "programs" subdirectory, change the filepath
   "/Users/jjares/Documents/research/Farm Subsidies/replication_materials" to the
   location of the replication materials directory on your current machine
4. Run "Create Post-Stratification Weights.do", which will create the intermediate
   output "Regression Data with Post-Strat Weights.dta"
5. Run the remaining three programs
   * "Create Regression Tables.do" creates all regression tables in the main
     manuscript, Online Appendix, and Further Supplemental Information.
   * "Create Figure 2.R" produces Figure 2 in the main manuscript.
   * "Regressions with Post-Stratification Weights.Rmd" produces Figures 7-10
     in the "Further Supplemental Information" document that is also stored in this 
     APSR Dataverse entry.

Steps for producing descriptive statistics figures and tables:
1. Install Python 3 and Jupyter lab. Installing the package manager Anaconda is
   an especially convenient way to do this, as Anaconda comes with both Python 3
   and Jupyter, and allows you to create a separate environment for this replication
   that won't interfere with your current Python installation. Instructions for
   installing Anaconda on various operating systems are available here:
   https://docs.anaconda.com/anaconda/install/index.html
2. (Optional) Create an Anaconda environment for installing Python packages for
   this replication file. The following syntax will create a conda environment:

       conda create -n anzia_et_al_2022
       conda activate anzia_et_al_2022
       conda config --env --add channels conda-forge
       conda config --env --set channel_priority strict

3. Install the Python modules used in this replication file. Note that geopandas
   is only required for recreating Figures 4 and 5 from the Online Appendix. Also
   note that if you intend to use a conda environment for managing packages for
   this replication file, activate the conda environment before installing the
   following packages ("conda activate anzia_et_al_2022", if your environment is
   named "anzia_et_al_2022"). Below we provide the name of each Python package
   used in this replication file, as well as syntax for installing it using conda.
   Versions of modules used by the authors are provided in parentheses.
   Note that this installation syntax may not work on all operating systems.

   (a) * numpy (1.19.2)
       * conda install numpy
   (b) * pandas (1.1.3)
       * conda install -c anaconda pandas
   (c) * janitor (0.20.14)
       * conda install -c conda-forge pyjanitor
   (d) * pandas_flavor (0.2.0)
       * conda install -c conda-forge pandas-flavor
   (e) * matplotlib (3.3.2)
       * conda install -c conda-forge matplotlib
   (f) * seaborn (0.11.0)
       * conda install -c anaconda seaborn
   (g) * scipy (1.5.2)
       * conda install -c anaconda scipy
   (h) * textwrap3 (0.9.2)
       * conda install -c conda-forge textwrap3
   (i) * geopandas (0.10.2)
       * conda install python=3 geopandas

4. (Optional) If you are using a new conda environment, you can add it to your
   Jupyter configuration. Open a  new terminal (on MacOS) or a command prompt
   (Windows), and activate your conda environment (e.g. "conda activate anzia_et_al_2022").
   The following syntax should add your conda environment to your Jupyter configuration:

   conda install ipykernel
   ipython kernel install --user --name=anzia_et_al_2022

5. Run the three Jupyter notebooks. Open a terminal / command prompt and navigate
   to the replication materials directory (use "cd" to change your directory),
   and use the syntax "jupyter lab" to launch Jupyter. Navigate to the "programs"
   subdirectory of this replication folder, and then click on the name of a
   .ipynb file to open a particular notebook. If you've added a conda
   environment to your Jupyter configuration, you can select the environment as
   a kernel by clicking on "Kernel" from the menu bar located on top of the
   notebook, and then selecting "Change kernel" from the dropdown list. Jupyter
   notebooks can be run from start to finish by selecting the "Kernel" dropdown
   menu from the top ribbon in the Jupyter notebook, and then selecting "Restart
   Kernel and Run All Cells". The notebook can also be run cell-by-cell by
   clicking a cell to select it, and then either clicking the rotated triangle
   (the "play button") in the menu at the top of the notebook, or by using the
   keyboard shortcut for running a single cell: shift+return on MacOS, and
   Ctrl + Enter on Windows.

   The three notebook produce the following figures:
   * "Aggregate Farm Program Payments over Time.ipynb"
       * Figure 1 (Main Text)
       * Figure 1 (Further Supplemental Information)
   * "Create Maps of Respondent and Sampling Frame Locations.ipynb"
       * Figure 4 (Online Appendix)
       * Figure 5 (Online Appendix)
   * "Survey Respondent Descriptive Statistics.ipynb"
       * Figures 1-3 in the Online Appendix
       * Figure 4 from Further Supplemental Information
       * Table 5 from Further Supplemental Information

----------------------------------------------------------------------------------

Note: Table 2 from the main text, Online Appendix Table 1, and Online Appendix Table 2 are not 
covered by these replication materials. We are unable to post replication data for these three 
tables due to the need to withhold personally identifiable information, in addition to stipulations 
of data use agreements for proprietary data sources. Researchers interested in obtaining the source 
data for any of these three tables may reach out to the authors directly.
